import { Widget, _decorator, Node, Sprite, SpriteFrame, Label, Tween, tween, v3 } from 'cc';
import { DtoReward } from '../dto/DtoReward';
import { ItemType } from '../enum/ItemType';
import { CoinMgr } from '../manager/CoinMgr';
import { ItemMgr } from '../manager/ItemMgr';
import { ResMgr } from '../manager/ResMgr';
import { InputBlock } from '../misc/InputBlock';
import { UIBase } from '../scriptBase/UIBase';
import { CoinItem } from '../uiItem/CoinItem';
import { CfgItem } from '../config/CfgItem';
import { GameUtil, shopData } from '../util/GameUtil';
import { UI } from '../enum/UI';
const { ccclass, property, requireComponent } = _decorator;

@ccclass('UI/UIGetReward')
@requireComponent(Widget)
export class UIGetReward extends UIBase {


    private rewardArr: DtoReward[] = []

    private tw: Tween<Node>

    private curReward: DtoReward = null
    public set CurReward(reward: DtoReward) {

    }

    protected onLoad(): void {
        // this.icon = this.findComp('Icon', Sprite)
        // this.lbCnt = this.findComp('LbCnt', Label)
        // this.coinItem = this.findComp('CoinItem', CoinItem)
    }

    public onOpen(data?: any): void {
        // this.coinItem.init(CoinMgr.CurCoin)
        // this.rewardArr = data
        // this.CurReward = this.rewardArr.shift()

        // let item:shopData = GameUtil.getNewItemId(true);
        // GameUtil.loadImage("itemImg/unLock/" + item.lockImage, this.icon);
    }

    protected onBtnCloseClick(): void {
        this.close()
    }

    protected async onBtnTripleGetClick() {
        // const len: number = this.rewardArr.length
        // if (len <= 0) {
        //     await this.getItem(3)
        //     this.close()
        // } else {
        //     await this.getItem(3)
        //     this.CurReward = this.rewardArr.shift()
        // }

    }

    protected async onBtnNormalGetClick() {

        // const len: number = this.rewardArr.length
        // if (len <= 0) {
        //     await this.getItem()
        //     this.close()
        // } else {
        //     await this.getItem()
        //     this.CurReward = this.rewardArr.shift()
        // }
    }

    private getItem(time: number = 1) {
        // return new Promise<void>((resolve, reject) => {
        //     const { itemId, cnt } = this.curReward
        //     const itemType: ItemType = ItemMgr.getType(itemId)

        //     this.lbCnt.string = `x${time * cnt}`

        //     ItemMgr.updateItem(itemId, time * cnt)

        //     switch (itemType) {
        //         case ItemType.Coin:
        //             this.coinItem.updateCoin(this.coinItem.Coin + time * cnt)
        //             InputBlock.setActive(2)
        //             this.scheduleOnce(() => {
        //                 resolve()
        //             }, 2)
        //             break;
        //         case ItemType.Skill:
        //             resolve()
        //             break
        //         case ItemType.Collection:
        //             resolve()
        //         default:
        //             break;
        //     }
        // })
    }

}


